package com.example.zhc36.fragment.apadter;

import android.support.annotation.NonNull;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.zhc36.fragment.R;
import com.example.zhc36.fragment.bean.Featurebean;

import java.util.List;

public class RvadapterFragment extends RecyclerView.Adapter<RvadapterFragment.Viewholder> {

    private List<Featurebean> listData;


    public RvadapterFragment(List<Featurebean> listData) {

        this.listData = listData;
    }

    @Override
    public int getItemCount() {
        return listData.size();
    }


    @NonNull
    @Override
    public Viewholder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.item_news, viewGroup, false);

        return new Viewholder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull Viewholder viewholder, int i) {
        Featurebean bean = listData.get(i);
        viewholder.Setdata(bean);


    }


    public static class Viewholder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv;



        public Viewholder(@NonNull View itemView) {
            super(itemView);
            iv = itemView.findViewById(R.id.iv);
            tv = itemView.findViewById(R.id.tv);


        }

        public void Setdata(Featurebean bean) {
            tv.setText(bean.getName());


        }
    }
}
